package hibernate;

/**
 *
 * @author Igor Kovb
 */
public class ProductCategory extends DBEntity {

    /***
     * Класс категорий продуктов. Поля: ИД, описание.
     * Используется для задания категории продукта.
     * Играет роль перечисления с всеми типами продуктов
     */
    private String description;

    ProductCategory() {}

    private ProductCategory (int id, String description){
        this.setId(id);
        this.setDescription(description);
    }
    
    private final static ProductCategory CUSTOM = new ProductCategory(1, "Свое (укажите в описании)");
    private final static ProductCategory IT = new ProductCategory(2, "Компьютерная техника");
    private final static ProductCategory STATIONERY = new ProductCategory(3, "Канцелярские товары");
    private final static ProductCategory FOOD = new ProductCategory(4, "Пищевые продукты");
    

    /**
     * @return the custom product category object
     */
    public static ProductCategory GET_CUSTOM_CATEGORY(){
        ProductCategory res = new ProductCategory(CUSTOM.getId(), CUSTOM.getDescription());
        return res;
    }
    
    /**
     * @return the IT product category object
     */
    public static ProductCategory GET_IT_CATEGORY(){
        ProductCategory res = new ProductCategory(IT.getId(), IT.getDescription());
        return res;
    }
    
    /**
     * @return the stationary product category object
     */
    public static ProductCategory GET_STATIONERY_CATEGORY(){
        ProductCategory res = new ProductCategory(STATIONERY.getId(), STATIONERY.getDescription());
        return res;
    }
    
    /**
     * @return the food product category object
     */
    public static ProductCategory GET_FOOD_CATEGORY(){
        ProductCategory res = new ProductCategory(FOOD.getId(), FOOD.getDescription());
        return res;
    }

    
    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
    /**
     * I realize that now this is only cover on simple String comparison, but
     * comparison of classes is my level of responsibility 
     * and the outside world must compare objects using the equals method
     * without even thinking of the elements, of which our class consist
     * @param p
     * @return 
     */
    public boolean equals(ProductCategory p) {
        boolean res = false;
        if (this.getDescription().equals(p.getDescription())) {
            res = true;
        }
        return res;
    }
    
    @Override
    public boolean equals(Object o) {
        boolean res = false;
        if (o instanceof ProductCategory) {
            ProductCategory p = (ProductCategory) o;
            res = this.equals(p);
        }
        return res;
    }
}
